package autocode

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
    "github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
    autocodeReq "github.com/flipped-aurora/gin-vue-admin/server/model/autocode/request"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
    "github.com/flipped-aurora/gin-vue-admin/server/service"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
)

type ProgramInfoApi struct {
}

var programInfoService = service.ServiceGroupApp.AutoCodeServiceGroup.ProgramInfoService


// CreateProgramInfo 创建ProgramInfo
// @Tags ProgramInfo
// @Summary 创建ProgramInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.ProgramInfo true "创建ProgramInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /programInfo/createProgramInfo [post]
func (programInfoApi *ProgramInfoApi) CreateProgramInfo(c *gin.Context) {
	var programInfo autocode.ProgramInfo
	_ = c.ShouldBindJSON(&programInfo)
	if err := programInfoService.CreateProgramInfo(programInfo); err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteProgramInfo 删除ProgramInfo
// @Tags ProgramInfo
// @Summary 删除ProgramInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.ProgramInfo true "删除ProgramInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /programInfo/deleteProgramInfo [delete]
func (programInfoApi *ProgramInfoApi) DeleteProgramInfo(c *gin.Context) {
	var programInfo autocode.ProgramInfo
	_ = c.ShouldBindJSON(&programInfo)
	if err := programInfoService.DeleteProgramInfo(programInfo); err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteProgramInfoByIds 批量删除ProgramInfo
// @Tags ProgramInfo
// @Summary 批量删除ProgramInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除ProgramInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /programInfo/deleteProgramInfoByIds [delete]
func (programInfoApi *ProgramInfoApi) DeleteProgramInfoByIds(c *gin.Context) {
	var IDS request.IdsReq
    _ = c.ShouldBindJSON(&IDS)
	if err := programInfoService.DeleteProgramInfoByIds(IDS); err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateProgramInfo 更新ProgramInfo
// @Tags ProgramInfo
// @Summary 更新ProgramInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.ProgramInfo true "更新ProgramInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /programInfo/updateProgramInfo [put]
func (programInfoApi *ProgramInfoApi) UpdateProgramInfo(c *gin.Context) {
	var programInfo autocode.ProgramInfo
	_ = c.ShouldBindJSON(&programInfo)
	if err := programInfoService.UpdateProgramInfo(programInfo); err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindProgramInfo 用id查询ProgramInfo
// @Tags ProgramInfo
// @Summary 用id查询ProgramInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query autocode.ProgramInfo true "用id查询ProgramInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /programInfo/findProgramInfo [get]
func (programInfoApi *ProgramInfoApi) FindProgramInfo(c *gin.Context) {
	var programInfo autocode.ProgramInfo
	_ = c.ShouldBindQuery(&programInfo)
	if err, reprogramInfo := programInfoService.GetProgramInfo(programInfo.ID); err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"reprogramInfo": reprogramInfo}, c)
	}
}

// GetProgramInfoList 分页获取ProgramInfo列表
// @Tags ProgramInfo
// @Summary 分页获取ProgramInfo列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query autocodeReq.ProgramInfoSearch true "分页获取ProgramInfo列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /programInfo/getProgramInfoList [get]
func (programInfoApi *ProgramInfoApi) GetProgramInfoList(c *gin.Context) {
	var pageInfo autocodeReq.ProgramInfoSearch
	_ = c.ShouldBindQuery(&pageInfo)
	if err, list, total := programInfoService.GetProgramInfoInfoList(pageInfo); err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败", c)
    } else {
        response.OkWithDetailed(response.PageResult{
            List:     list,
            Total:    total,
            Page:     pageInfo.Page,
            PageSize: pageInfo.PageSize,
        }, "获取成功", c)
    }
}
